package com.burges.net.ml.supervisedLearning

import org.apache.flink.api.scala.{DataSet, ExecutionEnvironment}
import org.apache.flink.ml.classification.SVM
import org.apache.flink.ml.common.LabeledVector

/**
  * 创建人    BurgessLee 
  * 创建时间   2020/2/27 
  * 描述      SVM应用实例
  */
object SVMDemo {

	def main(args: Array[String]): Unit = {
		val environment = ExecutionEnvironment.getExecutionEnvironment
		//指定训练数据集和测试数据集
		val trainLibSvmFile: String = ""
		val testLibSvmFile: String = ""
		//读取训练LibSVM数据集
		val trainingDS: DataSet[LabeledVector] = environment.readLibSVM(trainLibSvmFile)
		//创建svm算子，并制定block为10
		val svm: SVM = SVM().setBlocks(10)
		//训练模型
		svm.fit(trainingDS)
		//读取SVM测试数据集，对模型进行评估
		val testingDs = environment.readLibSVM(testLibSvmFile).map(_.vector)
		//通过predict方法对测试数据集进行预测，产生预测结果
		val predictionDs: DataSet[Any] = svm.predict(testingDs)
	}

}
